home *** CD-ROM | disk | FTP | other *** search
- //////////////////////////////////////////////////
- //
- // ADOBE SYSTEMS INCORPORATED
- // Copyright 2002 Adobe Systems Incorporated
- // All Rights Reserved
- //
- // NOTICE: Adobe permits you to use, modify, and
- // distribute this file in accordance with the terms
- // of the Adobe license agreement accompanying it.
- // If you have received this file from a source
- // other than Adobe, then your use, modification,
- // or distribution of it requires the prior
- // written permission of Adobe.
- //
- //////////////////////////////////////////////////
-
- //////////////////////////////////////////////////
- // Create Shadow.js
- //
- // DESCRIPTION
- //
- // This script demonstrates the use of Effect types and creating and naming
- // groups. This script creates a shadow for any selected object and gives it
- // effects and depths. It groups them so that the shadow moves alongwith the
- // object and also names them as one group. Then it animates them holding at
- // each keyframe.
- //
- // HOW TO USE
- //
- // Create any object(s) and select it in the Composition.
- // Select Automation > Run Automation Scripts > Create Shadow.js
- //
- // You can then animate them as one object.
- // Note: Make sure your object is any color other than black which differs
- // from black considerably.
- //
- // The other alternative to do the same would be to create a layer underneath
- // the object. They would then be one object and grouping will not be required.
- //
- //////////////////////////////////////////////////
-
-
- // Main Code [Execution of script begins from here]
-
- // Check if any composition is open
- if(application.compositions.length > 0){
- comp = application.currentComposition;
- if(comp.selection.length >= 1){ // Checks if at least one object is selected
- var source = comp.selection[0]; // Store all selected objects in the array source
- application.currentComposition.saveSelection(); // saves the current selection
-
- createShadow(comp, source);// Function createShadow called
- // The current composition and the selected objects are passed as arguements.
-
- application.currentComposition.restoreSelection(); // restores the saved selection
- }
- else{ // If no objects are selected brings the Console window up
- Console.show();
- // Writes to the Console
- Console.write("Please select the objects to create shadow and run script again.\n");
- }
- }
- else{// if no composition open
- // opens a new composition
- comp = application.newComposition();
- Console.show();
- Console.write("New Composition opened\nPlease create and select the objects to create shadow of and run script again.\n");
- }
-
-
- // Add your own functions here
-
- //////////////////////////////////////////////////
- //
- // createShadow:
- //
- // Creates the shadow of the object passed to it groups them
- // and then animates treating them as one object.
- //
- // source: The currently selected objects which are passed to the function.
- // comp: The current composition.
- //
- //////////////////////////////////////////////////
-
- function createShadow(comp, source)
- {
- var shadow;// variable to store shadow of object
- var xdiff; // Variable to store the difference in x sizes of source and shadow
-
- // Determining the distance between the shadow and the source object
- if (source.size.x >= 0 && source.size.x <= 100){
- // if object size is between 0-100
- xdiff = 2;
- }
- else {// if object size is greater than 100
- xdiff = 3;
- }
-
- // Creating a duplicate object which is the shadow.
- shadow = source.duplicate();
-
- // Setting its start color of gradient without setting
- // the gradient type. This is how we can set a single color
- // for objects without gradient. We are setting black color
- // for the shadow here.
- shadow.layers[0].colorGradient.startColor.red = 0;
- shadow.layers[0].colorGradient.startColor.green = 0;
- shadow.layers[0].colorGradient.startColor.blue = 0;
-
- // Move the shadow size to give it a slight 3D Effect.
- shadow.size.x += xdiff;
-
- // Note: The shadow is created on top of the original object.
- // The order in which the objects get/are created determines
- // the z-order of the objects. But here since shadows are below
- // the original objects we use LMArrangeType to bring the object
- // in front.
-
- source.arrange(LMArrangeType.bringToFront);
- // We can also use bringToFront instead of bringForwards
- // here since we have only two objects
-
- // Give the Effect type emboss to the source.
- source.layers[0].effect.type = LMEffectType.emboss;
-
- // Set the depth of the layer for effect as 5.
- source.layers[0].effect.depth = 5;
- Console.write(source + "\n");
-
- // Note: Original object source and shadow move together so
- // we group them and then we can manipulate them as one object.
-
- // To group the shadow and the original source object
- // create an array of objects to group.
- var objstoGroup = new Array(source, shadow);
-
- // Using the group method of composition to group the array.
- var newGroup = comp.group(objstoGroup);
- Console.write(newGroup);
-
- // Naming the group using the name property.
- // Every object has a name property.
- newGroup.name = "myGroup";
- // if you have more than one object to name then you can
- // give it in a loop as "myGroup"+i.
- // This will name the objects as myGroup0, myGroup1 and so on.
-
- // Assigning the opacity to oriOpacity
- var oriOpacity = newGroup.opacity;
-
- // Starting the opacity stopwatch
- newGroup.stopwatch.opacity = true;
-
- // Assign the original opacity
- newGroup.opacity = oriOpacity;
-
- Scaling(newGroup, 3, 36, 10); // Function Scaling called
-
- // Note: In Automation scripts you refer to object through
- // the names you give them in the script. Unlike in player
- // scripts you refer to them through their names as they appear
- // on the timeline.
-
- // Opacity is 0
- newGroup.opacity = 0;
- }
-
- //////////////////////////////////////////////////
- // Scaling:
- //
- // Animates the object and its shadow as one object holding
- // keyframe at every scale change.
- //
- // myObject: The grouped object and shadow, now one object.
- // keyFrameRate: The rate at which the keyframes will be set.
- // frames: Total number of frames across which the object is animated
- // increment: The amount of scale increased every keyframe.
- //////////////////////////////////////////////////
-
- function Scaling(myObject, keyFrameRate, frames, increment)
- {
- var xscale = myObject.scale.x; // Variable for x scale.
- var yscale = myObject.scale.y; // Variable for y scale.
- var f, frame0; // Variables for setting current frame and first frame respectively.
-
- // Start the stopwatch for scaling.
- myObject.stopwatch.scale = true;
-
- // Since starting does not record the attribute assign
- // it again to record it's value
- myObject.scale.x = xscale ;
- myObject.scale.y = yscale ;
-
- // First frame is the current frame.
- frame0 = myObject.startFrame;
-
- // Loop for gradual increase in size of the object
- for( f=0 ; f <= frames ; f+=keyFrameRate){
- // Set the key frame at the current frame
- myObject.currentFrame = frame0 + f;
-
- // Increase opacity by increment value
- myObject.scale.x += increment;
- myObject.scale.y += increment;
- }
-
- // The keyframes set for the object can be accessed by using -
- // object.keyframes.attribute. Here myObject.keyframes.scale.
- var kfs = myObject.keyframes.scale;
-
- // To turn the boolean hold on for each keyframe looping through all
- // keyframes in the array kfs.
- for (var index = 0;index < kfs.length;++index)
- kfs[index].hold = true;
- }